﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Import Namespace="Microsoft.SharePoint.ApplicationPages" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls"
    Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ViewAllNotifications.aspx.cs"
    Inherits="JM.JCY.SharePointComponent.Layouts.SharePointComponent.ViewAllNotifications"
    DynamicMasterPageFile="~masterurl/default.master" %>

<asp:Content ID="PageHead" ContentPlaceHolderID="PlaceHolderAdditionalPageHead" runat="server">
</asp:Content>
<asp:Content ID="Main" ContentPlaceHolderID="PlaceHolderMain" runat="server">
    <script type="text/javascript">
        var mySelecteds = new Array();
        var CheckAllVal = false;
        var currentOPALL = true;
        $(document).ready(function () {
            readLoading();

            $("#<%=ButtonSetAsRead.ClientID %>").click(function () {
                if (ValidateSubmit()) {
                    var msg = "真的要把这些通知设为已读吗？";
                    showConfirm('', msg, CancelMyRedemption, CancelCall, null);
                }
                return false;
            });
        });

        function CancelMyRedemption() {
            var selectedIds = '';
            for (var i = 0; i < mySelecteds.length; i++) {

                if (mySelecteds[i] != 0) {
                    selectedIds = selectedIds + '/' + mySelecteds[i];
                }
            }
            CallServer("SetAsRead_" + $("#currIndex").val() + selectedIds, "content");
        }

        function CancelCall() {
        }

        function ValidateSubmit() {
            var ctl = document.getElementById('<%=gvNotification.ClientID %>');
            var checkboxNumber = 0;
            if (ctl != undefined) {
                var Controls = ctl.getElementsByTagName('input');

                for (var i = 1; i < Controls.length; i++) {
                    if (Controls[i].type == 'checkbox') {
                        if (Controls[i].checked == true) {
                            checkboxNumber++;

                        }
                    }
                }
                if (checkboxNumber == 0) {
                    showAlert('提示', '至少要选择一条信息。');
                    return false;
                }
            }
            return true;
        }

        function ReadAll() {
            mySelecteds = new Array();
            currentOPALL = true;
            var ctl = document.getElementById('<%=gvNotification.ClientID %>');
            var checkboxNumber = 0;
            if (ctl != undefined) {
                var Controls = ctl.getElementsByTagName('input');
                CheckAllVal = false;
                for (var i = 0; i < Controls.length; i++) {
                    if (i == 0) {
                        CheckAllVal = Controls[i].checked;
                    } else {
                        if (Controls[i].type == 'checkbox') {
                            Controls[i].checked = !CheckAllVal;
                            $("input[id='" + Controls[i].id + "']").click();
                        }
                    }
                }
            }
            currentOPALL = false;
        }

        function selected(id, obj) {
            var selectedValue;
            if (currentOPALL == true) {
                selectedValue = CheckAllVal;
            } else {
                selectedValue = obj.checked;
            }
            var isexist = false;
            for (var i = 0; i < mySelecteds.length; i++) {
                if (mySelecteds[i] == id) {
                    isexist = true;
                    if (selectedValue == false) {
                        mySelecteds[i] = 0;
                    }
                }
            }
            if (isexist == false && selectedValue == true) {
                mySelecteds[mySelecteds.length] = id;
            }
        }

        function ReceiveCallback(arg, context) {
            if (arg.indexOf("|ox|") > 0) {
                var r = arg.split("|ox|");
                $("#content").html(r[0]);
                if (parseInt(r[1]) == 0) {
                    $("#divPage1").hide();
                    $("#divPage2").hide();
                    $("#content").html("你还没有可显示的通知信息。");
                } else {
                    if (parseInt(r[1]) > 1) {
                        $("#divPage1").show();
                        $("#divPage2").show();
                    } else {
                        $("#divPage1").hide();
                        $("#divPage2").hide();
                    }
                    $("#content").show();
                    $("#lastIndex").val(r[1]);

                    var p = r[2].split("@");
                    document.getElementById('<%= spPager1.ClientID %>').innerHTML = p[0];
                    document.getElementById('<%= spPager2.ClientID %>').innerHTML = p[1];
                    SetCurrentLink($("#currLinkToSet").val(), $("#<%= lbFirst.ClientID %>"), $("#<%= lbPrev.ClientID %>"), $("#<%= lbNext.ClientID %>"), $("#<%= lbLast.ClientID %>"),
                    $("#<%= lbFirst2.ClientID %>"), $("#<%= lbPrev2.ClientID %>"), $("#<%= lbNext2.ClientID %>"), $("#<%= lbLast2.ClientID %>"));
                }
            } else {
                showAlert('', arg);
                return false;
            }
        }

        function readLoading() {
            var pagesNum = $("#<%=HiddenFieldPageNum.ClientID %>").val();
            $("#currIndex").val("1")
            if (pagesNum == 0) {
                HideResult(true);
            } else {
                if (pagesNum > 1) {
                    $("#divPage1").show();
                    $("#divPage2").show();
                } else {
                    $("#divPage1").hide();
                    $("#divPage2").hide();
                }
                $("#content").show();
                $("#lastIndex").val(pagesNum);

                //HiddenFieldPagerText
                var PagerText = $("#<%=HiddenFieldPagerText.ClientID %>").val();
                var p = PagerText.split("@");
                document.getElementById('<%= spPager1.ClientID %>').innerHTML = p[0];
                document.getElementById('<%= spPager2.ClientID %>').innerHTML = p[1];
                SetCurrentLink($("#currLinkToSet").val(), $("#<%= lbFirst.ClientID %>"), $("#<%= lbPrev.ClientID %>"), $("#<%= lbNext.ClientID %>"), $("#<%= lbLast.ClientID %>"),
                    $("#<%= lbFirst2.ClientID %>"), $("#<%= lbPrev2.ClientID %>"), $("#<%= lbNext2.ClientID %>"), $("#<%= lbLast2.ClientID %>"));
            }

        }

        function HideResult(hide) {
            if (hide == true) {
                $("#divPage1").hide();
                $("#divPage2").hide();
                $("#content").hide();
            }
            else {
                $("#divPage1").show();
                $("#divPage2").show();
                $("#content").show();
            }
        }

        function JCYNotiTurnPage(pageIndex) {
            var currentIndex = parseInt($("#currIndex").val());
            if (currentIndex == pageIndex) {
                return;
            } else {
                turnPage(pageIndex);
            }
        }

        function JCYNotiTurnPagePrev() {
            var currentIndex = parseInt($("#currIndex").val());
            var targetIndex = 0;
            if (currentIndex == 1) {
                return;
            } else {
                targetIndex = currentIndex - 1;
            }
            JCYNotiTurnPage(targetIndex);
        }

        function JCYNotiTurnPageNext() {
            var currentIndex = parseInt($("#currIndex").val());
            var lastIndex = $("#lastIndex").val();
            var targetIndex = 0;
            if (currentIndex == lastIndex) {
                return;
            } else {
                targetIndex = currentIndex + 1;
            }
            JCYNotiTurnPage(targetIndex);
        }

        function JCYNotiTurnPageLast() {
            var lastIndex = $("#lastIndex").val();
            var currentIndex = parseInt($("#currIndex").val());
            if (currentIndex < lastIndex) {
                JCYNotiTurnPage(lastIndex);
            } else {
                return;
            }
        }
    </script>
    <div>
        <table class="main" width="100%" cellpadding="0" cellspacing="0" border="0">
            <tr>
                <td valign="top" width="98%">
                    <table class="content" width="98%">
                        <tr>
                            <td style="padding: 5px;" colspan="2">
                                <table width="100%" class="title">
                                    <tr>
                                        <td>
                                            <h2 class="title">
                                                <asp:Label ID="lblTitle" runat="server" Text="查看所有通知"></asp:Label>
                                            </h2>
                                        </td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <asp:Button ID="ButtonSetAsRead" runat="server" Text="改为已读" />
                            </td>
                            <td align="right">
                                <div class="pagination" id="divPage1">
                                    <asp:LinkButton ID="lbFirst" runat="server" Text="<< 第一页 |" OnClientClick="JCYNotiTurnPage(1);return false;"></asp:LinkButton>
                                    <asp:LinkButton ID="lbPrev" runat="server" Text="< 上一页 |" OnClientClick='JCYNotiTurnPagePrev();return false;'></asp:LinkButton>
                                    <span id="spPager1" runat="server"></span>
                                    <asp:LinkButton ID="lbNext" runat="server" Text="| 下一页 >" OnClientClick='JCYNotiTurnPageNext();return false;'></asp:LinkButton>
                                    <asp:LinkButton ID="lbLast" runat="server" Text="| 最后一页 >>" OnClientClick='JCYNotiTurnPageLast();return false;'></asp:LinkButton>
                                    <input id="currIndex" type="text" value="1" style="display: none;" />
                                    <input id="lastIndex" type="text" style="display: none;" />
                                    <input id="currLinkToSet" type="text" value="1" style="display: none;" />
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="2">
                                <div id="content">
                                    <asp:GridView ID="gvNotification" runat="server" AutoGenerateColumns="False" BorderWidth="0px"
                                        GridLines="Horizontal" Width="100%" DataKeyNames="NotificationId" OnRowDataBound="gvNotification_RowDataBound">
                                        <Columns>
                                            <asp:TemplateField HeaderText="">
                                                <ItemTemplate>
                                                    <asp:CheckBox ID="CheckBoxRead" runat="server" />
                                                </ItemTemplate>
                                                <HeaderStyle />
                                                <HeaderStyle Width="4%" />
                                                <ItemStyle Width="4%" />
                                                <HeaderTemplate>
                                                    <asp:CheckBox ID="CheckBoxReadAll" runat="server" />
                                                </HeaderTemplate>
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="内容">
                                                <ItemTemplate>
                                                    <asp:Label ID="lbContent" runat="server"></asp:Label>
                                                </ItemTemplate>
                                                <HeaderStyle />
                                                <ItemStyle HorizontalAlign="Left" />
                                            </asp:TemplateField>
                                            <asp:TemplateField HeaderText="状态">
                                                <ItemTemplate>
                                                    <asp:Label ID="lbStatus" runat="server"></asp:Label>
                                                </ItemTemplate>
                                                <HeaderStyle Width="8%" />
                                                <ItemStyle Width="8%" />
                                            </asp:TemplateField>
                                            <asp:BoundField DataField="ActualCreationTime" DataFormatString="{0:yyyy年MM月dd日}"
                                                HeaderText="时间">
                                                <HeaderStyle HorizontalAlign="Center" Width="12%" />
                                                <ItemStyle HorizontalAlign="Center" Width="12%" />
                                            </asp:BoundField>
                                        </Columns>
                                        <HeaderStyle CssClass="GridHeadStyle" HorizontalAlign="Left" />
                                        <RowStyle CssClass="GridRowStyle" HorizontalAlign="Left" VerticalAlign="Middle" />
                                    </asp:GridView>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td align="right" colspan="2">
                                <div class="pagination" id="divPage2">
                                    <asp:LinkButton ID="lbFirst2" runat="server" Text="<< 第一页 |" OnClientClick="JCYNotiTurnPage(1);return false;"></asp:LinkButton>
                                    <asp:LinkButton ID="lbPrev2" runat="server" Text="< 上一页 |" OnClientClick='JCYNotiTurnPagePrev();return false;'></asp:LinkButton>
                                    <span id="spPager2" runat="server"></span>
                                    <asp:LinkButton ID="lbNext2" runat="server" Text="| 下一页 >" OnClientClick='JCYNotiTurnPageNext();return false;'></asp:LinkButton>
                                    <asp:LinkButton ID="lbLast2" runat="server" Text="| 最后一页 >>" OnClientClick='JCYNotiTurnPageLast();return false;'></asp:LinkButton>
                                </div>
                            </td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </div>
    <asp:HiddenField ID="HiddenFieldStaffId" runat="server" />
    <asp:HiddenField ID="HiddenFieldPagerText" runat="server" />
    <asp:HiddenField ID="HiddenFieldPageNum" runat="server" />
</asp:Content>
<asp:Content ID="PageTitle" ContentPlaceHolderID="PlaceHolderPageTitle" runat="server">
    查看所有通知
</asp:Content>
<asp:Content ID="PageTitleInTitleArea" ContentPlaceHolderID="PlaceHolderPageTitleInTitleArea"
    runat="server">
</asp:Content>
